<?php
defined('IN_PHPCMS') or exit('No permission resources.');
class index {
	private $db;
	function __construct() {
		$this->db = pc_base::load_model('score_model');
		$this->renzheng_enroll_model = pc_base::load_model('renzheng_enroll_model');
 	}
	
	public function init() {
		
	}
	//考试系统分数回传接口
	function responsescore(){
		$jsondata = $_POST;

		if(empty($jsondata['token']) || empty($jsondata['uid']) || empty($jsondata['score']) || empty($jsondata['rid']) || empty($jsondata['name']) || empty($jsondata['gread'])){
			$msg['returnCode'] = '100002';
			$msg['returnDesc'] = '参数验证错误';
			echo json_encode($msg);
			return;
		}

		$token = md5($jsondata['rid'].$jsondata['uid'].$jsondata['name'].$jsondata['gread'].'sobey@2014');
		if($token != $jsondata['token']){
			$msg['returnCode'] = '100001';
			$msg['returnDesc'] = '密匙验证错误';
			//header('Content-Type: application/json'); 
			echo json_encode($msg);
			return;
		}

		if($this->renzheng_enroll_model->update(array('rz_score'=>$jsondata['score'], 'rz_theory_pass'=>$jsondata['theorypass']), array('rz_id'=>$jsondata['rid']))){
			$msg['returnCode'] = '000000';
			$msg['returnDesc'] = '处理成功';
			echo json_encode($msg);
			return;
		}else{
			$msg['returnCode'] = '200000';
			$msg['returnDesc'] = '处理失败';
			echo json_encode($msg);
			return;
		}

		$msg['returnCode'] = '999999';
		$msg['returnDesc'] = '未知错误';
		echo json_encode($msg);
		return;
	}

	function test(){
		$ch = curl_init();
		//curl_setopt ($ch, CURLOPT_URL, 'http://127.0.0.6/index.php?m=score&c=index&a=responsescore');
		curl_setopt ($ch, CURLOPT_URL, 'http://113.142.30.140/login.aspx');
		//curl_setopt ($ch, CURLOPT_URL, 'http://113.142.30.140/Server/Interface/HttpPost.aspx');
		//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

		curl_setopt($ch, CURLOPT_POST, 1);
		$data = array ("uid" => "19", "name"=>"test", "token"=>"fdasfdsa4vsd", 'gread'=>"0010", "clientTimestamps"=>"13243245342", "upath"=>"http://v9.help.phpcms.cn/statics/images/help_img/logo.png");
		//$data = array ("uid" => "1", "name"=>"admin", "upath"=>"http://v9.help.phpcms.cn/statics/images/help_img/logo.png");
		$post_data = json_encode($data,JSON_UNESCAPED_SLASHES);
		
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		$file_contents = curl_exec($ch);
		curl_close($ch);
	}
}
?>